// Copyright 2004-2011 Castle Project - http://www.castleproject.org/
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Castle.MonoRail.Views.Brail.Tests
{
    using NUnit.Framework;
    using TestSiteBrail.Components;

    [TestFixture]
	public class DslLayoutFixture : BaseViewOnlyTestFixture
	{
        protected override void BeforEachTest()
        {
            ViewComponentFactory.Inspect(typeof(GridComponent).Assembly);
        }
        
        [Test]
		public void ComponentOuputUsingDsl()
		{
            Layout = "dsl";
            PropertyBag["items"] = new[]
            {
                "Ayende",
                "Rahien"
            }; 
			var expected =
				"<html><body><table><tr><th>Names</th></tr><tr><td>Ayende</td></tr><tr><td>Rahien</td></tr></table></body></html>";
			ProcessView_StripRailsExtension("dsl/testSubViewWithComponents.rails");
			AssertReplyEqualTo(expected);
		}

		[Test]
		public void LayoutAndChildOuputUsingDsl()
		{
            PropertyBag["SayHelloTo"] = "Harris";
		    Layout = "dsl";
            var expected = "<html><p>Hello, Harris</p></html>";
			ProcessView_StripRailsExtension("dsl/testSubViewOutput.rails");
			AssertReplyEqualTo(expected);
		}

		[Test]
		public void XmlDsl()
		{
            PropertyBag["items"] = new[]
            {
                "Ayende",
                "Rahien"
            };    
			var expected =
				"<?xml version=\"1.0\" encoding=\"utf-16\"?><rss><channel><title>RSS DSL</title><item><title>Title: Ayende</title><description>Description: Ayende</description></item><item><title>Title: Rahien</title><description>Description: Rahien</description></item></channel></rss>";
			ProcessView_StripRailsExtension("dsl/testXml.rails");
			AssertReplyEqualTo(expected);
		}
	}
}